Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename graphql export to g #19

Merged
merged 10 commits into from
Feb 3, 2025
Merged

Rename graphql export to g #19

merged 10 commits into from
Feb 3, 2025

Conversation

emmatown
Copy link
Member

This renames the graphql export to g for two reasons:

  • More concise reading/writing schemas
  • To avoid conflicts with exports named graphql from libraries such as Relay, GraphQL Code Generator and gql.tada that use the variable name graphql to declare GraphQL operations

The graphql export still exists but is now deprecated and may be removed in a future release.

To quickly update usages of the graphql export in your project to use g:

  1. Navigate to node_modules/@graphql-ts/schema/dist/declarations/src/schema-api-alias.d.ts in your editor ("Go to Definition" will not take you to the correct file)
  2. Use "Rename Symbol" to rename graphql to g, this will update usages of graphql to g
  3. Change this deprecated alias back from g to graphql (avoid using "Rename Symbol" again because you want to preserve the updates you made in step 2)

You can similarly use "Rename Symbol" to quickly rename your own custom defined graphql to g.


In case anyone is curious about the usage of the esoteric TypeScript-specific syntax of export import ... = ... in schema-api-alias.d.ts, this does a subtle thing which is allowing us to alias the variable while also adding a JSDoc comment and preserving the types rather than just the values. Note two other similar syntaxes are insufficient:

  • export const graphql = _graphql would mean that the types (e.g. graphql.ObjectType<...>/etc.) would be lost and only the runtime properties would be accessible
  • export * as graphql from '...'/export { _graphql as graphql }/etc. doesn't allow for attaching a JSDoc comment to the alias to have the @deprecated tag and other text

Copy link

socket-security bot commented Jan 31, 2025

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/@graphql-ts/[email protected]

View full report↗︎

@emmatown emmatown force-pushed the rename-graphql-to-g branch 2 times, most recently from 95da2a4 to 0c6cd63 Compare January 31, 2025 06:36
@emmatown emmatown force-pushed the rename-graphql-to-g branch 5 times, most recently from 6770a17 to d06b3bc Compare February 3, 2025 03:49
@emmatown emmatown marked this pull request as ready for review February 3, 2025 04:41
@emmatown emmatown merged commit d79115e into main Feb 3, 2025
5 checks passed
@emmatown emmatown deleted the rename-graphql-to-g branch February 3, 2025 04:48
@github-actions github-actions bot mentioned this pull request Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant